


//
//  CommentCell.m
//  第六组电影项目
//
//  Created by mini on 14-7-3.
//  Copyright (c) 2014年 www.skedu.com.cn北京尚德智远科技有限公司. All rights reserved.
//

#import "CommentCell.h"
#import "CommentInfoModel.h"
@implementation CommentCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle=UITableViewCellSelectionStyleNone;
       // self.backgroundColor=[UIColor brownColor];
        [self initSubViews];
        // Initialization code
    }
    return self;
}
-(void)initSubViews
{
    //头像
    userImage=[[UIImageView alloc]initWithFrame:CGRectZero];
    [self.contentView addSubview:userImage];
    
    //单元格
    cellBG=[[UIImageView alloc]initWithFrame:CGRectZero];
    UIImage *original=[UIImage imageNamed:@"movieDetail_comments_frame"];
    UIImage *newImage=[original stretchableImageWithLeftCapWidth:original.size.width/2 topCapHeight:original.size.height/2];
    cellBG.image=newImage;
    [self.contentView addSubview:cellBG];
    
    //昵称
    nickName=[[UILabel alloc]initWithFrame:CGRectZero];
    nickName.font=[UIFont boldSystemFontOfSize:12];
    nickName.textColor=[UIColor grayColor];
    [cellBG addSubview:nickName];
    
    //评分
    rating=[[UILabel alloc]initWithFrame:CGRectZero];
    rating.font=[UIFont boldSystemFontOfSize:12];
    rating.textColor=[UIColor grayColor];
    [cellBG addSubview:rating];
    
    //评论
    _content=[[UILabel alloc]initWithFrame:CGRectZero];
    _content.numberOfLines=0;
    _content.font=[UIFont boldSystemFontOfSize:16];
    _content.textColor=[UIColor blackColor];
    [cellBG addSubview:_content];
    
}
-(void)layoutSubviews
{
    userImage.frame=CGRectMake(10, 10, 30, 30);
    [userImage setImageWithURL:[NSURL URLWithString:_commentInfoModel.userImage]];
    
    nickName.frame=CGRectMake(30, 2, 110, 20);
    nickName.text=_commentInfoModel.nickname;
    
    rating.frame=CGRectMake(220,0,80,20);
    rating.text=_commentInfoModel.rating;
    
    //方法1
    CGSize size = [_content sizeThatFits:CGSizeMake(220, MAXFLOAT)];
    double height = size.height;
    
    //方法2
//    NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:_content.font,NSFontAttributeName, nil];
//
//    double height=[_commentInfoModel.content boundingRectWithSize:CGSizeMake(220, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size.height;
    
    _content.frame=CGRectMake(nickName.left, nickName.bottom, 220,height);
    _content.text=_commentInfoModel.content;
    
    cellBG.frame=CGRectMake(userImage.right, userImage.top, 260, nickName.height+_content.height+10);
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
